/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include "stm32f4xx.h"
#include "LCD_SETUP.h"
#include "Icon_Pics.h"
#include "stm32f4_discovery.h"
#include "stm32f4_discovery_lcd.h"
#include "stmpe811qtr.h"
#include "LCD_Touch_Calibration.h"
#include "touch_Detect.h"


/* Private define ------------------------------------------------------------*/
/*Calibration accuracy, + /-x pixels*/
#define CALIBRATION_RANGE      (10)

/*1st calibration point  position*/
#define CAL_POINT1_X           (20)
#define CAL_POINT1_Y           (20)

/*2nd calibration point position*/
#define CAL_POINT2_X          (300)
#define CAL_POINT2_Y           (20)

/*3rd calibration point position*/
#define CAL_POINT3_X           (20)
#define CAL_POINT3_Y          (220)

/*4th calibration point position*/
#define CAL_POINT4_X          (300)
#define CAL_POINT4_Y          (220)

/*calibration test point position*/
#define TST_POINT_X           (160)
#define TST_POINT_Y           (120)

#define TOUCH_AD_VALUE_MAX    (4000)
#define TOUCH_AD_VALUE_MIN    (100)

#define ABS(X)  ((X) > 0 ? (X) : -(X))

/* External function prototypes -----------------------------------------------*/
extern void delay(__IO uint32_t nCount);

/* Private variables ---------------------------------------------------------*/
Point_Struct point_new, point_old;
char playPause=0;
char onSettingsPage =0;
char onTimeSet = 0;
char onAlarm = 0;
char musicPlaying=0;
char phonePlay=0;
__IO uint16_t Color=0x31CA;
__IO uint16_t backgroundColor=White;
char selectColor = 0;
char selectBackColor = 0;
char selectUnit = 0;
uint16_t newPointX = 0;
uint16_t newPointY = 0;
int count = 182;
int position=0;
int toggleTime =0;
char alarmDraw=0;

void touchDetect(void) 
{
	
 
  //uint8_t text[50];

  TS_STATE *pstate = NULL;
  char i;
  point_new.x = 0;
  point_new.y = 0;
  point_old.x = 0;
  point_old.y = 0;
  
  
  
      pstate = IOE_TS_GetState();
   
    
      point_new.x = pstate->X;
      point_new.y = pstate->Y;
      
     
      //     Music Note Animation   //
      if(playPause==1&&position<80&&!onSettingsPage&&!onTimeSet)
      {
        
        LCD_SetTextColor(backgroundColor);
        LCD_DrawCircle((280-(position-1)), 145, 3);
        LCD_DrawLine((283-(position-1)), 135, 10, 1);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((280-(position-1)-i), 142+i , 2+(i*2), 0);
        }
        LCD_DrawLine((280-(position-1)-3), 145 , 6, 0);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((280-(position-4)+i), 146+i , 6-(i*2), 0);
        }
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((283-(position-1)), 135+i, 8, 0);
        }
        LCD_DrawCircle((288-(position-1)), 145, 3);
        LCD_DrawLine((291-(position-1)), 135, 10, 1);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((288-(position-1)-i), 142+i , 2+(i*2), 0);
        }
        LCD_DrawLine((288-(position-1)-3), 145 , 6, 0);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((288-(position-4)+i), 146+i , 6-(i*2), 0);
        }
        
        
        
        LCD_SetTextColor(Color);
        LCD_DrawCircle((280-position), 145, 3);
        LCD_DrawLine((283-position), 135 , 10, 1);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((280-position-i), 142+i , 2+(i*2), 0);
        }
        LCD_DrawLine((280-position-3), 145 , 6, 0);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((280-position+i-3), 146+i , 6-(i*2), 0);
        }
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((283-position), 135+i, 8, 0);
        }
        LCD_DrawCircle((288-position), 145, 3);
        LCD_DrawLine((291-position), 135 , 10, 1);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((288-position-i), 142+i , 2+(i*2), 0);
        }
        LCD_DrawLine((288-position-3), 145 , 6, 0);
        for(i = 0; i<3;i++)
        {
          LCD_DrawLine((288-position+i-3), 146+i , 6-(i*2), 0);
        }
        position++;
      }  
      
      
      if(position==67)
      {
        LCD_SetTextColor(backgroundColor);
        for(i = 0; i<15;i++)
        {
          LCD_DrawLine((288-position-11), 135+i , 16, 0);
        }
        LCD_SetTextColor(Color);
        position=0;
        
      }
    if(onAlarm==1)
    {
      
      if(toggleTime%10==0)
      {
        
        if(alarmDraw==0)
        {
          drawTime();
          alarmDraw=1;
        }
        else
        {
          LCD_SetFont(&Font12x12);
          LCD_ClearLine(LINE(4));
          LCD_ClearLine(LINE(5));
          LCD_ClearLine(LINE(6));
          LCD_ClearLine(LINE(7));
          LCD_ClearLine(LINE(8));
          LCD_ClearLine(LINE(9));
          LCD_ClearLine(LINE(10));
          alarmDraw=0;
        }
      }
      toggleTime++; 
    }
    if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_15)!=Bit_RESET)
    {
      if(musicPlaying==0)
      {
        if(onAlarm==0)
        {
          drawPauseIcon();
        }
        playPause=1;
        mediaButton(playPause);
        musicPlaying=1;
      }
    }
    if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_15)==Bit_RESET)
    {
      if(musicPlaying==1)
      {
        if(onAlarm==0)
        {
          drawPlayIcon();
        }
         playPause=0;
         LCD_SetTextColor(backgroundColor);
         for(i = 0; i<15;i++)
         {
           LCD_DrawLine(210, 135+i , 82, 0);
         }
         LCD_SetTextColor(Color);
         position =0;
        mediaButton(playPause);
        musicPlaying=0;
        
      }
    }
    if(point_new.x!=newPointX&&point_new.y!=newPointY&&pstate->TouchDetected)
    {
         newPointX = point_new.x;
         newPointY = point_new.y;

    /* If AD result is abnormal, then LCD show nothing */
    if ((point_new.x > TOUCH_AD_VALUE_MAX) 
        || (point_new.x < TOUCH_AD_VALUE_MIN)
        || (point_new.y > TOUCH_AD_VALUE_MAX)
        || (point_new.y < TOUCH_AD_VALUE_MIN)) {
      //continue;					
    }
  
		
   //sprintf((char*)text,"   x_AD = %d ",point_new.x);
    //LCD_DisplayStringLine(LINE(4),text);
		
    //sprintf((char*)text,"   y_AD = %d ",point_new.y);
    //LCD_DisplayStringLine(LINE(5),text);
	/*Calculate coordinates*/
    if(!onSettingsPage&&!onTimeSet&&!onAlarm)
    {
          //Volume up button//
	  if((point_new.x>690&&point_new.x<820)&&(point_new.y>3450&&point_new.y<3600))
	  {
		if(count<195)
		{
                  GPIO_SetBits(GPIOA, GPIO_Pin_10);
                  count=count+13;
                  changeVolume(count);
                  GPIO_ResetBits(GPIOA, GPIO_Pin_10);
		}
	  }
          //Volume down button//
	  if((point_new.x>3360&&point_new.x<3480)&&(point_new.y>3450&&point_new.y<3600))
	  {
		if(count>0)
		{
                   GPIO_SetBits(GPIOA, GPIO_Pin_13);
                   count=count-13;
                   changeVolume(count); 
                   GPIO_ResetBits(GPIOA, GPIO_Pin_13);
		}
	  }
 
    //Previous Button//
      if((point_new.x>1170&&point_new.x<1530)&&(point_new.y>2720&&point_new.y<3250))
      {
        GPIO_SetBits(GPIOB, GPIO_Pin_6);
        previousTouched();
        GPIO_ResetBits(GPIOB, GPIO_Pin_6);
      }
      //Play Button//
      if((point_new.x>700&&point_new.x<1100)&&(point_new.y>2820&&point_new.y<3250))
      {
        GPIO_SetBits(GPIOB, GPIO_Pin_5);
        playTouched();
        //delay(30);
        mediaButton(playPause);
        GPIO_ResetBits(GPIOB, GPIO_Pin_5);
      }
      //Next Button//
      if((point_new.x>240&&point_new.x<600)&&(point_new.y>2820&&point_new.y<3250))
      {
         GPIO_SetBits(GPIOB, GPIO_Pin_4);
        nextTouched();
        GPIO_ResetBits(GPIOB, GPIO_Pin_4);
      }
        //Settings Button//
      if((point_new.x>240&&point_new.x<600)&&(point_new.y>430&&point_new.y<910))
      {
        isOnSettings(0);
        settingsPage();
      }
    }
    else if(onSettingsPage&&!onTimeSet&&!onAlarm)
    {
      //Back Button//
      if((point_new.x>3340&&point_new.x<3700)&&(point_new.y>430&&point_new.y<910))
      {
          LCD_Clear(backgroundColor); 
          setScreenLayout();
          isOnSettings(1);
          drawTime();
          drawTemp();
          drawDate();
          drawAlarm();
          changeVolume(count);
          onSettingsPage = 0;
      }
      
      //       Text Color Touch Detector      //
      if((point_new.x>3350&&point_new.x<3750)&&(point_new.y>1385&&point_new.y<1700))
      {
          Color=Grey;
          selectColor = 0;
          settingsPage();
      }
      if((point_new.x>2415&&point_new.x<3000)&&(point_new.y>1385&&point_new.y<1700))
      {
        Color=Blue;
          selectColor = 1;
          settingsPage();
      }
      if(((point_new.x>1700&&point_new.x<2200)&&(point_new.y>1385&&point_new.y<1700))&&backgroundColor!=Red)
      {
          Color=Red;
          selectColor = 2;
          settingsPage();
      }
      if(((point_new.x>645&&point_new.x<1260)&&(point_new.y>1385&&point_new.y<1700))&&backgroundColor!=Black)
      {
          Color=Black;
          selectColor = 3;
          settingsPage();
      }
      if(((point_new.x>3350&&point_new.x<3750)&&(point_new.y>1845&&point_new.y<2100))&&backgroundColor!=Cyan)
      {
          Color=Cyan;
          selectColor = 4;
          settingsPage();
      }
       if((point_new.x>2380&&point_new.x<3000)&&(point_new.y>1845&&point_new.y<2100))
      {
          Color=Green;
          selectColor = 5;
          settingsPage();
      }
       if((point_new.x>1400&&point_new.x<2200)&&(point_new.y>1845&&point_new.y<2100))
      {
          Color=Magenta;
          selectColor = 6;
          settingsPage();
      }
       if((point_new.x>500&&point_new.x<1260)&&(point_new.y>1845&&point_new.y<2100))
      {
          Color=Yellow;
          selectColor = 7;
          settingsPage();
      }
      
      //     Background Color Touch Detector   ///
      if((point_new.x>3230&&point_new.x<3830)&&(point_new.y>2550&&point_new.y<2890))
      {
          if(Color == White)
          {
            Color = Black;
          }
          backgroundColor=White;
          LCD_SetBackColor(White);
          selectBackColor = 0;
          settingsPage();
      }
       if((point_new.x>2280&&point_new.x<2870)&&(point_new.y>2550&&point_new.y<2890))
      {
          if(Color == Black || Color == Grey)
          {
            Color = White;
          }
          backgroundColor=Black;
          LCD_SetBackColor(Black);
          selectBackColor = 1;
          settingsPage();
      }
       if((point_new.x>1430&&point_new.x<1900)&&(point_new.y>2550&&point_new.y<2890))
      {
          if(Color == Cyan)
          {
            Color = Black;
          }
          backgroundColor=Cyan;
          LCD_SetBackColor(Cyan);
          selectBackColor = 2;
          settingsPage();
      }
      if((point_new.x>620&&point_new.x<1040)&&(point_new.y>2550&&point_new.y<2890))
      {
          if(Color == Red)
          {
            Color = Black;
          }
          backgroundColor=Red;
          LCD_SetBackColor(Red);
          selectBackColor = 3;
          settingsPage();
      }
      
      
      //     Temperature Unit Touch Detector     //
      if((point_new.x>2750&&point_new.x<3230)&&(point_new.y>3250&&point_new.y<3660))
      {
          selectUnit=0;
          setTempUnits(selectUnit);
          settingsPage();
      }
      if((point_new.x>1445&&point_new.x<2230)&&(point_new.y>3250&&point_new.y<3660))
      {
          selectUnit=1;
          setTempUnits(selectUnit);
          settingsPage();
      }
      //     Time Set Button       //
      if((point_new.x>240&&point_new.x<600)&&(point_new.y>430&&point_new.y<910))
      {
         isOnSettings(1);
         setTimePosition(1);
         timeSetPage();
      }
      //   Device Connection    //
      if((point_new.x>430&&point_new.x<840)&&(point_new.y>3090&&point_new.y<3590))
      {
         GPIO_SetBits(GPIOB, GPIO_Pin_5);
         delay(250);
         GPIO_ResetBits(GPIOB, GPIO_Pin_5);
      }
    }  
    else if(onTimeSet&&!onAlarm)
    {
         //            Back Button on time set page     //
      if((point_new.x>3340&&point_new.x<3700)&&(point_new.y>430&&point_new.y<910))
      {
          isOnSettings(0);
          setTimePosition(0);
          settingsPage();
          onTimeSet=0;
      }
      //               Hour up button on time set page    //
      if((point_new.x>2660&&point_new.x<2950)&&(point_new.y>450&&point_new.y<700))
      {
          incrementHour();
          delay(30);
      }
      //              Hour down button on time set page   //
      if((point_new.x>2660&&point_new.x<2950)&&(point_new.y>2460&&point_new.y<2870))
      {
          decrementHour();
          delay(30);
      }
      //               Minute up button on time set page    //
      if((point_new.x>1230&&point_new.x<1600)&&(point_new.y>450&&point_new.y<700))
      {
          incrementMin();
          delay(30);
      }
      //              Minute down button on time set page   //
      if((point_new.x>1230&&point_new.x<1600)&&(point_new.y>2460&&point_new.y<2870))
      {
          decrementMin();
          delay(30);
      }
      //               Half day up button on time set page    //
      if((point_new.x>350&&point_new.x<600)&&(point_new.y>450&&point_new.y<700))
      {
          changeHalfDay();
          delay(30);
      }
      //              Half day down button on time set page   //
      if((point_new.x>350&&point_new.x<600)&&(point_new.y>2460&&point_new.y<2870))
      {
         changeHalfDay();
         delay(30);
      }

      //              Up button for day of week   //
      if((point_new.x>3080&&point_new.x<3370)&&(point_new.y>2900&&point_new.y<3130))
      {
         incrementDayofWeek();
         delay(30);
      }
      //              Down button for day of week  //
      if((point_new.x>3080&&point_new.x<3370)&&(point_new.y>3320&&point_new.y<3560))
      {
        decrementDayofWeek();
         delay(30);
      }
      //              Up button for Month   //
      if((point_new.x>1930&&point_new.x<2150)&&(point_new.y>2900&&point_new.y<3130))
      {
         incrementMonth();
         delay(30);
      }
      //              Down Button for Month   //
      if((point_new.x>1930&&point_new.x<2150)&&(point_new.y>3320&&point_new.y<3560))
      {
         decrementMonth();
         delay(30);
      }
      //             Up Button for day of month  //
      if((point_new.x>1210&&point_new.x<1460)&&(point_new.y>2900&&point_new.y<3130))
      {
         incrementDayofMonth();
         delay(30);
      }
      //              Down Button for day of month    //
      if((point_new.x>1210&&point_new.x<1460)&&(point_new.y>3320&&point_new.y<3560))
      {
        decrementDayofMonth();
         delay(30);
      }
      //              Up Button for Year   //
      if((point_new.x>580&&point_new.x<880)&&(point_new.y>2900&&point_new.y<3130))
      {
         incrementYear();
         delay(30);
      }
      //              Down Button for Year  //
      if((point_new.x>580&&point_new.x<880)&&(point_new.y>3320&&point_new.y<3560))
      {
         decrementYear();
         delay(30);
      }
    }
    else if(onAlarm)
    {
      //Back Button//
      if((point_new.x>3340&&point_new.x<3700)&&(point_new.y>430&&point_new.y<910))
      {
          LCD_Clear(backgroundColor); 
          setScreenLayout();
          isOnSettings(1);
          onAlarm=0;
          isOnAlarmScreen(onAlarm);
          drawTime();
          drawTemp();
          drawDate();
          drawAlarm();
          changeVolume(count);
          
          alarmDraw=0;
          toggleTime=0;
          
      }
    }

		

    if (point_new.x >= LCD_PIXEL_WIDTH) {
      point_new.x = LCD_PIXEL_WIDTH -1;
    }
    if (point_new.y >= LCD_PIXEL_HEIGHT) {
      point_new.y = LCD_PIXEL_HEIGHT -1;
    }
	if ((point_old.x == 0) && (point_old.y == 0)) {
      point_old.x = point_new.x;
      point_old.y = point_new.y;			
    } else {
      point_old.x = point_new.x;
      point_old.y = point_new.y;	
    }  
  }
}

void isOnAlarm()
{
  uint8_t text[50];
  onAlarm = 1; 
  isOnAlarmScreen(onAlarm);
  LCD_Clear(backgroundColor);
  drawBackIcon();
  LCD_SetFont(&Font16x24);
  sprintf((char*)text,"        ALARM!");
  LCD_DisplayStringLine(LINE(18),text);
  if(musicPlaying==0)
  {
    GPIO_SetBits(GPIOB, GPIO_Pin_5);
     delay(30);
    GPIO_ResetBits(GPIOB, GPIO_Pin_5);
  }
  else
  {
    delay(30);
  }
}

//  LCD Screen Layout for time settings   //
void timeSetPage()
{
  
  LCD_Clear(backgroundColor);
  char i;
  
  
        //   Buttom up for time   ///
	for(i = 0; i<10;i++)
	{
            LCD_DrawLine(90-i, 20+i, 1+(i*2), 0);
	}
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(210-i, 20+i, 1+(i*2), 0);
	}
         for(i = 0; i<10;i++)
	{
            LCD_DrawLine(290-i, 20+i, 1+(i*2), 0);
	}
        
        //     Buttom down for time   //
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(90-i, 155-i, 1+(i*2), 0);
	}
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(210-i, 155-i, 1+(i*2), 0);
	}
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(290-i, 155-i, 1+(i*2), 0);
	}
        
        //   Buttom up for date  ///
	for(i = 0; i<10;i++)
	{
            LCD_DrawLine(60-i, 177+i, 1+(i*2), 0);
	}
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(160-i, 177+i, 1+(i*2), 0);
	}
         for(i = 0; i<10;i++)
	{
            LCD_DrawLine(214-i, 177+i, 1+(i*2), 0);
	}
         for(i = 0; i<10;i++)
	{
            LCD_DrawLine(273-i, 177+i, 1+(i*2), 0);
	}
        
        //     Buttom down for date   //
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(60-i, 218-i, 1+(i*2), 0);
	}
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(160-i, 218-i, 1+(i*2), 0);
	}
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(214-i, 218-i, 1+(i*2), 0);
	}
        for(i = 0; i<10;i++)
	{
            LCD_DrawLine(273-i, 218-i, 1+(i*2), 0);
	}
        
  drawBackIcon();
  drawTime();
  drawDate();
  onTimeSet=1;
  delay(30);
}



// LCD Screen Layout of Settings Page
void settingsPage()
{
  uint8_t text[50];
  LCD_Clear(backgroundColor); 
  

        
          
        LCD_SetTextColor(Color);  
        LCD_SetFont(&Font16x24);
	
	/*    Setting up Date Format  */
	sprintf((char*)text,"      Settings");
        LCD_DisplayStringLine(LINE(1),text);
        drawBackIcon();
        drawClockIcon();
        drawSBOCK();
        LCD_SetFont(&Font12x12);
        sprintf((char*)text," Text Color:");
        LCD_DisplayStringLine(LINE(5),text);
        LCD_SetFont(&Font8x12);
        LCD_SetTextColor(Black);
        sprintf((char*)text,"                             Black ");
        LCD_DisplayStringLine(LINE(7),text);
        LCD_SetTextColor(Red);
        sprintf((char*)text,"                   Red");
        LCD_DisplayStringLine(LINE(7),text);
        LCD_SetTextColor(Blue);
        sprintf((char*)text,"           Blue");
        LCD_DisplayStringLine(LINE(7),text);
        LCD_SetTextColor(Grey);
        sprintf((char*)text,"  Grey");
        LCD_DisplayStringLine(LINE(7),text);
        LCD_SetTextColor(Yellow);
        sprintf((char*)text,"                             Yellow ");
        LCD_DisplayStringLine(LINE(9),text);
        LCD_SetTextColor(Magenta);
        sprintf((char*)text,"                   Magenta");
        LCD_DisplayStringLine(LINE(9),text);
        LCD_SetTextColor(Green);
        sprintf((char*)text,"           Green");
        LCD_DisplayStringLine(LINE(9),text);
        LCD_SetTextColor(Cyan);
        sprintf((char*)text,"  Cyan");
        LCD_DisplayStringLine(LINE(9),text);
      
        LCD_SetTextColor(Color);
        LCD_SetFont(&Font12x12);
        sprintf((char*)text," Background Color:");
        LCD_DisplayStringLine(LINE(11),text);
        LCD_SetFont(&Font8x12);
        sprintf((char*)text,"  White     Black     Cyan     Red");
        LCD_DisplayStringLine(LINE(13),text);
        
        LCD_SetFont(&Font12x12);
        sprintf((char*)text," Weather Units:");
        LCD_DisplayStringLine(LINE(15),text);
        LCD_SetFont(&Font8x12);
        sprintf((char*)text,"  Fahrenheit       Celcius");
        LCD_DisplayStringLine(LINE(17),text);
        
        if(selectColor==0)
        {
          LCD_DrawRect(10, 81, 41, 20);
        }
	if(selectColor==1)
        {
          LCD_DrawRect(80, 81, 44, 20);
        }
        if(selectColor==2)
        {
          LCD_DrawRect(145, 81, 37, 20);
        }
        if(selectColor==3)
        {
          LCD_DrawRect(227, 81, 46, 20);
        }
        if(selectColor==4)
        {
          LCD_DrawRect(10, 105, 41, 20);
        }
        if(selectColor==5)
        {
          LCD_DrawRect(80, 105, 55, 20);
        }
        if(selectColor==6)
        {
          LCD_DrawRect(145, 105, 68, 20);
        }
        if(selectColor==7)
        {
          LCD_DrawRect(227, 105, 61, 20);
        }
        
        //  Square Selector for Background Color  //
        if(selectBackColor==0)
        {
          LCD_DrawRect(10, 152, 50, 20);
        }
       
        if(selectBackColor==1)
        {
          LCD_DrawRect(89, 152, 50, 20);
        }
        if(selectBackColor==2)
        {
          LCD_DrawRect(170, 152, 40, 20);
        }
        if(selectBackColor==3)
        {
          LCD_DrawRect(241, 152, 35, 20);
        }
        
        //  Square Selector for Temp. Unit //
        
        
        if(selectUnit ==0)
        {
          LCD_DrawRect(10, 200, 86, 20);
        }
        if(selectUnit == 1)
        {
          LCD_DrawRect(145, 200, 65, 20);
        }
  
  onSettingsPage = 1;
  delay(30);
}
//Function for changing volume up and down in increments
void changeVolume(int count)
{
	char i;
	LCD_SetFont(&Font16x24);
	LCD_ClearLine(LINE(19));
	LCD_ClearLine(LINE(20));
	for(i = 0; i<5;i++)
	{
            LCD_DrawLine(40, 218+i , 15, 0);
	}
          
        for(i = 0; i<5;i++)
	{
            LCD_DrawLine(265, 218+i , 15, 0);
        }
        
        for(i = 0; i<5;i++)
	{
            LCD_DrawLine(270+i, 213, 15, 1);
	}
	LCD_DrawLine(60, 220 , 195, 0);
	for(i=0;i<3;i++)
	{
            LCD_DrawLine(60, 218+i , count, 0);
	}
	for(i=0;i<3;i++)
	{
            LCD_DrawLine(60, 221+i , count, 0);
	}
       delay(30);
}

// Function for play button press, changes to pause button//
void playTouched()
{ 
  //char i;
  if(playPause==1)
  {
    drawPausePressedIcon();
    /*
      LCD_SetTextColor(backgroundColor);
        for(i = 0; i<15;i++)
        {
          LCD_DrawLine(210, 135+i , 82, 0);
        }
        LCD_SetTextColor(Color);
    drawPlayIcon();
    playPause = 0;
    position =0;
    musicPlaying=0;*/
  }
  else
  {
    drawPlayPressedIcon();
    //drawPauseIcon();
     //playPause = 1;
      //musicPlaying=1;
  }
  delay(30);
}
void nextTouched()
{
  drawNextPressedIcon();
  delay(30);
  drawNextIcon();
}
void previousTouched()
{
  drawPreviousPressedIcon();
  delay(30);
  drawPreviousIcon();
}
